package org.xfc.components;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

import org.xfc.testing.XUITestCase;

public class XActionLabelTest
	extends XUITestCase
{
	private JFrame 			frame;
	private XActionLabel	label;
	
	protected void setUp()
		throws Exception
	{
		frame = new JFrame("XActionLabelTest");
		frame.setBounds(100, 100, 300, 300);
		
		label = new XActionLabel();
		
		frame.getContentPane().setLayout(new FlowLayout());
		frame.getContentPane().add(label);
		
		frame.setVisible(true);
		
		waitFor(locateShowing("XActionLabelTest"));
	}

	protected void tearDown()
		throws Exception
	{
		frame.dispose();
		frame = null;
	}

	public void testActionFired()
	{
		final boolean[] result = new boolean[1];
		
		label.setText("Test action label");
		label.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				result[0] = true;
			}
		});
		
		click(label);
		
		assertThat(result[0], eq(true));
	}
	
	public void testSetEnabled()
	{
		final boolean[] result = new boolean[1];
		
		label.setEnabled(false);
		label.setText("Test action label");
		label.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				result[0] = true;
			}
		});
		
		click(label);
		
		assertThat(result[0], eq(false));
	}

}
